package xddq

import (
	"fmt"
	"time"
	D "websocket_apn/define"
	"websocket_apn/log"
	"websocket_apn/proto"
)

// 处理山海万象组队信息
func (xd *XdDriver) CheckMountainSeaTeamInfoData(allInfo D.MountainSeaTeamInfo) {
	CombatValue := xd.UserData.CurrentEquipmentInfo[xd.UserData.CurrentEquipmentIdx].CombatValue
	for _, info := range allInfo.Team {
		if info.UserID == xd.UserData.UserID {
			CombatValue = info.CombatValue
		}
	}
	log.Infof("山海万象-组队信息 CombatValue:%s %+v", D.GetCombatValueDesc(CombatValue), allInfo)
	if len(allInfo.Team) >= 3 {
		log.Infof("山海万象-已组队完成")
		xd.StopTaskByID(proto.S_MOUNTAIN_SEA_ENTER_TEAM)
		//五气朝元9A 92 14  万法归宗A4 92 14  四象神引AE 92 14    炼神还虚B8 92 14
		xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_MOUNTAIN_SEA_CHANGE_TEAM_SKILL, "08 A4 92 14"))
		xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_MOUNTAIN_SEA_DO_BATTLE, "08 C8 DC 01 10 89 4F 18 94 08"))
		time.Sleep(4 * time.Second)
		xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_MOUNTAIN_SEA_DO_BATTLE, "08 C8 DC 01 10 8A 4F 18 94 08"))
		time.Sleep(4 * time.Second)
		xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_MOUNTAIN_SEA_DO_BATTLE, "08 C8 DC 01 10 8B 4F 18 94 08"))
		time.Sleep(4 * time.Second)
		xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_MOUNTAIN_SEA_DO_BATTLE, "08 C8 DC 01 10 8C 4F 18 94 08"))
		time.Sleep(4 * time.Second)
		xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_MOUNTAIN_SEA_DO_BATTLE, "08 C8 DC 01 10 8D 4F 18 94 08"))
		time.Sleep(4 * time.Second)
		xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_MOUNTAIN_SEA_DO_BATTLE, "08 C8 DC 01 10 8E 4F 18 94 08"))
		time.Sleep(4 * time.Second)
		xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_MOUNTAIN_SEA_DO_BATTLE, "08 C8 DC 01 10 8F 4F 18 94 08"))
	} else {
		flag := false
		for _, info := range allInfo.Person {
			if info.CombatValue*10 > CombatValue*7 {
				flag = true
				log.Infof("山海万象-同意[%s]组队, 妖力%s", info.Name, D.GetCombatValueDesc(info.CombatValue))
				xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_MOUNTAIN_SEA_APPLY_JOIN_TEAM_AGREE, fmt.Sprintf("08 %s", info.UserID)))
			}
		}
		if !flag {
			log.Infof("山海万象-拒绝所有组队请求")
			xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_MOUNTAIN_SEA_APPLY_JOIN_TEAM_REFUSED, ""))
		}
	}
}
